package org.jeecg.extra.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 是否枚举常量.
 *
 * <p>是（value=1, code=Y）
 * <p>否（value=0, code=N）
 *
 * @author chao.xie
 * @version 1.0.0
 * @创建日期: 2024.01.10
 */
@Getter
@AllArgsConstructor
public enum YesOrNo {
    /** 是 */
    YES(1, "Y", "是"),

    /** 否 */
    NO(0, "N", "否");

    private Integer value;

    private String code;

    private String desc;

    public static YesOrNo getByCode(String code) {
        for (YesOrNo yesOrNo : YesOrNo.values()) {
            if (yesOrNo.getCode().equals(code)) {
                return yesOrNo;
            }
        }
        return null;
    }

    public static YesOrNo getByValue(Integer value) {
        for (YesOrNo yesOrNo : YesOrNo.values()) {
            if (yesOrNo.getValue().equals(value)) {
                return yesOrNo;
            }
        }
        return null;
    }
}
